package com.snb.play.dwebtoon.data;

import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class DTO_Cartoon extends JSonDataObjectBase {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1315L;

	public String TAG = getClass().getSimpleName();

	// public String id;
	// public ArrayList<DTO_Artist> artists;
	public String picture_artists;
	public String write_artists;
	// public String title;
	// public ArrayList<DTO_Genre> genres;
	public String genres;

	// public String titleImage;
	// public String englishTitle;
	// public String joinArtists;
	// public ArrayList<DTO_Category> categories;
	// public String introduction;

	public DTO_Cartoon(JSONObject aJsonObject) {
		@SuppressWarnings("unchecked")
		Iterator<Object> iterator = aJsonObject.keys();

		while (iterator.hasNext()) {
			Object obj = iterator.next();
			if (obj.toString().equalsIgnoreCase("artists")) {
				// this.artists = new ArrayList<DTO_Artist>();
				DTO_Artist lArtist = null;
				try {
					JSONArray lartists = aJsonObject.getJSONArray("artists");

					for (int i = 0; i < lartists.length(); i++) {
						lArtist = new DTO_Artist(lartists.getJSONObject(i));
						// this.artists.add(lArtist);
						if (lArtist.artistType.indexOf("picture") > -1) {
							this.picture_artists = lArtist.penName;
						} else {
							this.write_artists = lArtist.penName;
						}
					}
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}

			} else if (obj.toString().equalsIgnoreCase("genres")) {
				// this.genres = new ArrayList<DTO_Genre>();
				this.genres = "";
				DTO_Genre lGenre = null;
				try {
					JSONArray lGenres = aJsonObject.getJSONArray("genres");

					for (int i = 0; i < lGenres.length(); i++) {
						lGenre = new DTO_Genre(lGenres.getJSONObject(i));
						this.genres += lGenre.name;
						// this.genres.add(lGenre);
					}
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}

			} else if (obj.toString().equalsIgnoreCase("categories")) {
				// this.categories = new ArrayList<DTO_Category>();
				// DTO_Category lCategory = null;
				// try {
				// JSONArray lcategories =
				// aJsonObject.getJSONArray("categories");
				//
				// for (int i = 0; i < lcategories.length(); i++) {
				// lCategory = new DTO_Category(lcategories.getJSONObject(i));
				// this.categories.add(lCategory);
				// }
				// } catch (JSONException e) {
				// if (isDebug)
				// e.printStackTrace();
				// }
			} else {
				setMemberFiled(this, aJsonObject, obj.toString());
			}
		}

		printMembers();
		insertObjToDB();
	}

}
